package calc;

public class Calculator <T> implements ICalculator {

	@Override
	public Number add(Number x, Number y) throws ArithmeticException {

        if(x == null || y == null) {
           throw new CalculatorException("Method Calculador.add operate only on non null valuers.");
        }
      
        return x.doubleValue() + y.doubleValue();
       
	}

	@Override
	public Number subtract(Number x, Number y) throws ArithmeticException {
		  if(x == null || y == null) {
	           throw new CalculatorException("Method Calculador.subtract operate only on non null valuers.");
	        }
	      
	        return x.doubleValue() - y.doubleValue();
	}

	@Override
	public Number multiply(Number x, Number y) throws ArithmeticException {
		  if(x == null || y == null) {
	           throw new CalculatorException("Method Calculador.multiply operate only on non null valuers.");
	        }
	      
	        return x.doubleValue() * y.doubleValue();
	}

	@Override
	public Number divide(Number numerator, Number denominator){
		 
		  if(numerator == null ||denominator == null) {
		      throw new CalculatorException("Method Calculador.add operate only on non null valuers.");
		   }
		   
		 if (denominator.doubleValue() == 0){
		 	throw new ArithmeticException("Divisor can not be zero!");
		 }
	      
		 return numerator.doubleValue() / denominator.doubleValue();
		 
	}


}
